home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoDocument.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  39.9 KB  |  1,159 lines

  1. // -*- c-basic-offset: 4 -*-
  2. /* This file is part of the KDE project
  3.    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
  4.    Copyright (C) 2000-2005 David Faure <faure@kde.org>
  5.  
  6.    This library is free software; you can redistribute it and/or
  7.    modify it under the terms of the GNU Library General Public
  8.    License as published by the Free Software Foundation; either
  9.    version 2 of the License, or (at your option) any later version.
  10.  
  11.    This library is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.    Library General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU Library General Public License
  17.    along with this library; see the file COPYING.LIB.  If not, write to
  18.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19.  * Boston, MA 02110-1301, USA.
  20. */
  21.  
  22. #ifndef __ko_document_h__
  23. #define __ko_document_h__
  24.  
  25. class KoTextDocument;
  26. namespace std { }
  27. using namespace std;
  28. #include <qwmatrix.h>
  29.  
  30. #include <kparts/part.h>
  31. #include <kurl.h>
  32. #include <kservice.h>
  33. #include <KoGlobal.h>
  34. #include <KoUnit.h>
  35. #include <KoPageLayout.h>
  36. #include <koffice_export.h>
  37.  
  38. class QDomElement;
  39. class QDomDocument;
  40. class QXmlSimpleReader;
  41.  
  42. class KoStore;
  43. class KoMainWindow;
  44.  
  45. class KoChild;
  46. class KoDocumentChild;
  47. class KoView;
  48. class KoDocumentInfo;
  49. class DCOPObject;
  50. class KoOasisStyles;
  51. class KoXmlWriter;
  52. class KoOpenPane;
  53.  
  54. /**
  55.  *  The %KOffice document class
  56.  *
  57.  *  This class provides some functionality each %KOffice document should have.
  58.  *
  59.  *  @short The %KOffice document class
  60.  */
  61. class KOFFICECORE_EXPORT KoDocument : public KParts::ReadWritePart
  62. {
  63.     Q_OBJECT
  64.     Q_PROPERTY( QCString dcopObjectId READ dcopObjectId)
  65.     Q_PROPERTY( bool backupFile READ backupFile WRITE setBackupFile )
  66.  
  67. public:
  68.  
  69.     /**
  70.      *  Constructor.
  71.      * The first 4 arguments are the same as the ones passed to KParts::Factory::createPart.
  72.      *
  73.      * @param parentWidget the parent widget, in case we create a wrapper widget
  74.      *        (in single view mode).
  75.      *        Usually the first argument passed by KParts::Factory::createPart.
  76.      * @param widgetName name of the widget.
  77.      * @param parent may be another KoDocument, or anything else.
  78.      *        Usually the third argument of KParts::Factory::createPart.
  79.      * @param name is used to identify this document via DCOP so you may want to
  80.      *        pass a meaningful name here which matches the pattern [A-Za-z_][A-Za-z_0-9]*.
  81.      * @param singleViewMode determines whether the document may only have one view. In this case
  82.      *        the @p parent must be a QWidget derived class. KoDocument will then create a wrapper widget
  83.      *        (KoViewWrapperWidget) which is a child of @p parentWidget.
  84.      *        This widget can be retrieved by calling widget().
  85.      *
  86.      * @todo explain what the purpose of widgetName is.
  87.      */
  88.     KoDocument( QWidget* parentWidget,
  89.                 const char* widgetName,
  90.                 QObject* parent,
  91.                 const char* name,
  92.                 bool singleViewMode = false );
  93.  
  94.     /**
  95.      *  Destructor.
  96.      *
  97.      * The destructor does not delete any attached KoView objects and it does not
  98.      * delete the attached widget as returned by widget().
  99.      */
  100.     virtual ~KoDocument();
  101.  
  102.     /**
  103.      * Tells whether this document is in singleview mode. This mode can only be set
  104.      * in the constructor.
  105.      */
  106.     bool isSingleViewMode() const;
  107.  
  108.     /**
  109.      * Is the document embedded?
  110.      */
  111.     bool isEmbedded() const;
  112.  
  113.     /**
  114.      * Returns the action described action object. In fact only the "name" attribute
  115.      * of @p element is of interest here. The method searches first in the
  116.      * KActionCollection of the first view and then in the KActionCollection of this
  117.      * document.
  118.      * This allows %KOffice applications to define actions in both the view and the document.
  119.      * They should only define view-actions (like zooming and stuff) in the view.
  120.      * Every action which changes the document should be defined in the document.
  121.      *
  122.      * Please notice that KoDocument indirectly inherits KXMLGUIClient.
  123.      *
  124.      * @see KXMLGUIClient
  125.      * @see KXMLGUIClient::actionCollection
  126.      * @see KoView::action
  127.      */
  128.     virtual KAction *action( const QDomElement &element ) const;
  129.  
  130.     /**
  131.      * Returns the DOM document which describes the GUI of the
  132.      * first view.
  133.      */
  134.     virtual QDomDocument domDocument() const;
  135.  
  136.     /**
  137.      * @internal
  138.      */
  139.     virtual void setManager( KParts::PartManager *manager );
  140.  
  141.     /**
  142.      * Reimplemented from KParts::ReadWritePart for internal reasons
  143.      * (for the autosave functionality)
  144.      */
  145.     virtual bool openURL( const KURL & url );
  146.  
  147.     /**
  148.      * Opens the document given by @p url, without storing the URL
  149.      * in the KoDocument.
  150.      * Call this instead of openURL() to implement KoMainWindow's
  151.      * File --> Import feature.
  152.      *
  153.      * @note This will call openURL(). To differentiate this from an ordinary
  154.      *       Open operation (in any reimplementation of openURL() or openFile())
  155.      *       call isImporting().
  156.      */
  157.     bool import( const KURL &url );
  158.  
  159.     /**
  160.      * Saves the document as @p url without changing the state of the
  161.      * KoDocument (URL, modified flag etc.). Call this instead of
  162.      * KParts::ReadWritePart::saveAs() to implement KoMainWindow's
  163.      * File --> Export feature.
  164.      *
  165.      * @note This will call KoDocument::saveAs(). To differentiate this
  166.      *       from an ordinary Save operation (in any reimplementation of
  167.      *       saveFile()) call isExporting().
  168.      */
  169.     bool exp0rt( const KURL &url );
  170.  
  171.     /**
  172.      * @brief Sets whether the document can be edited or is read only.
  173.      *
  174.      * This recursively applied to all child documents and
  175.      * KoView::updateReadWrite is called for every attached
  176.      * view.
  177.      */
  178.     virtual void setReadWrite( bool readwrite = true );
  179.  
  180.     /**
  181.      * @brief Used by KoApplication, and by KoMainWindow, when no document exists yet.
  182.      *
  183.      * With the help of @p instance or KApplication::instance() this
  184.      * method figures out which .desktop file matches this application. In this
  185.      * file it searches for the "X-KDE-NativeMimeType" entry and returns it.
  186.      *
  187.      * @see KService
  188.      * @see KDesktopFile
  189.      */
  190.     static QCString readNativeFormatMimeType( KInstance *instance = 0 );
  191.  
  192.     /**
  193.      * Used by KoMainWindow, when no document exists yet.
  194.      *
  195.      * With the help of @p instance or KApplication::instance() this
  196.      * method figures out which .desktop file matches this application. In this
  197.      * file it searches for the "X-KDE-ExtraNativeMimeTypes" entry and returns it.
  198.      *
  199.      * @see KService
  200.      * @see KDesktopFile
  201.      */
  202.     static QStringList readExtraNativeMimeTypes( KInstance *instance = 0 );
  203.  
  204.     /**
  205.      * With the help of @p instance or KApplication::instance() this
  206.      * method figures out which .desktop file matches this application,
  207.      * and returns the KService instance for it.
  208.      */
  209.     static KService::Ptr readNativeService( KInstance *instance = 0 );
  210.  
  211.     /**
  212.      * setup the XML reader, so that we don't have to duplicate the code.
  213.      */
  214.     static void setupXmlReader( QXmlSimpleReader& reader, bool namespaceProcessing = false );
  215.  
  216.     /**
  217.      * To be preferred when a document exists. It is fast when calling
  218.      * it multiple times since it caches the result that readNativeFormatMimeType()
  219.      * delivers.
  220.      * This comes from the X-KDE-NativeMimeType key in the .desktop file
  221.      * You do NOT have to reimplement this (it is only virtual for kounavail).
  222.      */
  223.     virtual QCString nativeFormatMimeType() const;
  224.  
  225.     /**
  226.      * Returns the OASIS OpenDocument mimetype of the document, if supported
  227.      * This comes from the X-KDE-NativeOasisMimeType key in the .desktop file
  228.      */
  229.     QCString nativeOasisMimeType() const;
  230.  
  231.     /// Checks whether a given mimetype can be handled natively.
  232.     bool isNativeFormat( const QCString& mimetype ) const;
  233.  
  234.     /// Returns a list of the mimetypes considered "native", i.e. which can
  235.     /// be saved by KoDocument without a filter, in *addition* to the main one
  236.     virtual QStringList extraNativeMimeTypes() const;
  237.  
  238.     /// Enum values used by specialOutputFlag - note that it's a bitfield for supportedSpecialFormats
  239.     enum { /*SaveAsKOffice1dot1 = 1,*/ // old and removed
  240.            SaveAsDirectoryStore = 2,
  241.            SaveAsFlatXML = 4
  242.            // bitfield! next value is 8
  243.          };
  244.  
  245.     /**
  246.      * Return the set of SupportedSpecialFormats that the application wants to
  247.      * offer in the "Save" file dialog.
  248.      */
  249.     virtual int supportedSpecialFormats() const;
  250.  
  251.     /**
  252.      * Returns the actual mimetype of the document
  253.      */
  254.     QCString mimeType() const;
  255.  
  256.     /**
  257.      * @brief Sets the mime type for the document.
  258.      *
  259.      * When choosing "save as" this is also the mime type
  260.      * selected by default.
  261.      */
  262.     void setMimeType( const QCString & mimeType );
  263.  
  264.     /**
  265.      * @brief Set the format in which the document should be saved.
  266.      *
  267.      * This is called on loading, and in "save as", so you shouldn't
  268.      * have to call it.
  269.      *
  270.      * @param mimeType the mime type (format) to use.
  271.      * @param specialOutputFlag is for "save as older version" etc.
  272.      */
  273.     void setOutputMimeType( const QCString & mimeType, int specialOutputFlag = 0 );
  274.     QCString outputMimeType() const;
  275.     int specialOutputFlag() const;
  276.  
  277.     /**
  278.      * Returns true if this document was the result of opening a foreign
  279.      * file format and if the user hasn't yet saved the document (in any
  280.      * format).
  281.      *
  282.      * Used by KoMainWindow to warn the user when s/he lazily presses
  283.      * CTRL+S to save in the same foreign format, putting all his/her
  284.      * formatting at risk (normally an export confirmation only comes up
  285.      * with Save As).
  286.      *
  287.      * @param exporting specifies whether this is the setting for a
  288.      * File --> Export or File --> Save/Save As operation.
  289.      */
  290.     bool confirmNonNativeSave( const bool exporting ) const;
  291.     void setConfirmNonNativeSave( const bool exporting, const bool on );
  292.  
  293.     virtual bool wantExportConfirmation() const;
  294.  
  295.     /**
  296.      * Sets the error message to be shown to the user (use i18n()!)
  297.      * when loading or saving fails.
  298.      * If you asked the user about something and he chose "Cancel",
  299.      * set the message to the magic string "USER_CANCELED", to skip the error dialog.
  300.      */
  301.     void setErrorMessage( const QString& errMsg );
  302.  
  303.     /**
  304.      * Return the last error message. Usually KoDocument takes care of
  305.      * showing it; this method is mostly provided for non-interactive use.
  306.      * @since 1.4
  307.      */
  308.     QString errorMessage() const;
  309.  
  310.     /**
  311.      * Show the last error message in a message box.
  312.      * The dialog box will mention a saving problem.
  313.      * Note that save/saveFile takes care of doing it.
  314.      * @since 1.4
  315.      */
  316.     void showSavingErrorDialog();
  317.  
  318.     /**
  319.      * Show the last error message in a message box.
  320.      * The dialog box will mention a loading problem.
  321.      * openURL/openFile takes care of doing it, but not loadNativeFormat itself,
  322.      * so this is often called after loadNativeFormat returned false.
  323.      * @since 1.4
  324.      */
  325.     void showLoadingErrorDialog();
  326.  
  327.     /**
  328.      *  Create a new view for the document.
  329.      */
  330.     KoView *createView( QWidget *parent = 0, const char *name = 0 );
  331.  
  332.     /**
  333.      * Adds a view to the document.
  334.      *
  335.      * This calls KoView::updateReadWrite to tell the new view
  336.      * whether the document is readonly or not.
  337.      */
  338.     virtual void addView( KoView *view );
  339.  
  340.     /**
  341.      * Removes a view of the document.
  342.      */
  343.     virtual void removeView( KoView *view );
  344.  
  345.     /**
  346.      * @return a list of views this document is displayed in
  347.      */
  348.     const QPtrList<KoView> & views() const;
  349.  
  350.     /**
  351.      * @return number of views this document is displayed in
  352.      */
  353.     int viewCount() const;
  354.  
  355.     /**
  356.      * Reimplemented from KParts::Part
  357.      */
  358.     virtual KParts::Part *hitTest( QWidget *widget, const QPoint &globalPos );
  359.  
  360.     /**
  361.      *  Find the most nested child document which contains the
  362.      *  requested point. The point is in the coordinate system
  363.      *  of this part. If no child document contains this point, then
  364.      *  a pointer to this document is returned.
  365.      *
  366.      *  This function has to be overloaded if the document features child documents.
  367.      *
  368.      *  @param pos is in (unzoomed) document coordinates
  369.      *  @param matrix transforms points from the documents coordinate system
  370.      *         to the coordinate system of the requested point. This is used by
  371.      *         transformed child documents, see KoDocumentChild/KoChild.
  372.      *
  373.      *  @return Pointer to the document under the mouse at that position
  374.      */
  375.     virtual KoDocument *hitTest( const QPoint &pos, const QWMatrix& matrix = QWMatrix() );
  376.     /// Temporary API for accessing the view that calls hitTest.
  377.     /// Will be passed to hitTest() in 2.x.
  378.     /// Only call this from within hitTest()!
  379.     KoView* hitTestView();
  380.  
  381.     /**
  382.      *  Paints the whole document into the given painter object.
  383.      *
  384.      *  @param painter     The painter object onto which will be drawn.
  385.      *  @param rect        The rect that should be used in the painter object.
  386.      *  @param transparent If true then the entire rectangle is erased before painting.
  387.      *  @param view        The KoView is needed to fiddle about with the active widget, when painting children.
  388.      *  @param zoomX       The zoom value to be applied to X coordinates when painting.
  389.      *  @param zoomY       The zoom value to be applied to Y coordinates when painting.
  390.      */
  391.     virtual void paintEverything( QPainter &painter, const QRect &rect, bool transparent = false,
  392.                                   KoView *view = 0L, double zoomX = 1.0, double zoomY = 1.0 );
  393.  
  394.     /**
  395.      * @brief Generates a preview picture of the document
  396.      * @note The preview is used in the File Dialog and also to create the Thumbnail
  397.      */
  398.     virtual QPixmap generatePreview( const QSize& size );
  399.  
  400.     /**
  401.      *  Paints all of the documents children into the given painter object.
  402.      *
  403.      *  @param painter     The painter object onto which will be drawn.
  404.      *  @param rect        The rect that should be used in the painter object.
  405.      *  @param view        The KoView is needed to fiddle about with the active widget.
  406.      *  @param zoomX       The zoom value to be applied to X coordinates when painting.
  407.      *  @param zoomY       The zoom value to be applied to Y coordinates when painting.
  408.      *
  409.      *  @see #paintChild #paintEverything #paintContent
  410.      */
  411.     virtual void paintChildren( QPainter &painter, const QRect &rect, KoView *view, double zoomX = 1.0, double zoomY = 1.0 );
  412.  
  413.     /**
  414.      *  Paint a given child. Normally called by paintChildren().
  415.      *
  416.      *  @param child       The child to be painted.
  417.      *  @param painter     The painter object onto which will be drawn.
  418.      *  @param view        The KoView is needed to fiddle about with the active widget.
  419.      *  @param zoomX       The zoom value to be applied to X coordinates when painting.
  420.      *  @param zoomY       The zoom value to be applied to Y coordinates when painting.
  421.      *
  422.      *  @see #paintEverything #paintChildren #paintContent
  423.      */
  424.     virtual void paintChild( KoDocumentChild *child, QPainter &painter, KoView *view,
  425.                              double zoomX = 1.0, double zoomY = 1.0 );
  426.  
  427.     /**
  428.      *  Paints the data itself. Normally called by paintEverything(). It does not
  429.      *  paint the children.
  430.      *  It's this method that %KOffice Parts have to implement.
  431.      *
  432.      *  @param painter     The painter object onto which will be drawn.
  433.      *  @param rect        The rect that should be used in the painter object.
  434.      *  @param transparent If false the implementing method should fill the background.
  435.      *  @param zoomX       The zoom value to be applied to X coordinates when painting.
  436.      *  @param zoomY       The zoom value to be applied to Y coordinates when painting.
  437.      *
  438.      *  @see #paintEverything
  439.      */
  440.     virtual void paintContent( QPainter &painter, const QRect &rect, bool transparent = false,
  441.                                double zoomX = 1.0, double zoomY = 1.0 ) = 0;
  442.  
  443.     /**
  444.      * Called by koApplication to check for an autosave file in $HOME
  445.      */
  446.     bool checkAutoSaveFile();
  447.  
  448.     /**
  449.      * This setting indicates who is calling initDoc.
  450.      * Usually the app will want to
  451.      * - show the template dialog with 'everything' if InitDocAppStarting, InitDocFileClose or InitDocEmbedded
  452.      * - show the template dialog with 'templates only' if InitDocFileNew
  453.      * - create an empty document with default settings if InitDocEmpty
  454.      */
  455.     enum InitDocFlags { InitDocAppStarting, InitDocFileNew, InitDocFileClose, InitDocEmbedded, InitDocEmpty };
  456.  
  457.     /**
  458.      * Initializes an empty document (display the template dialog!).
  459.      * You have to overload this method to initialize all your document variables.
  460.      * @param flags see InitDocFlags
  461.      * @param parentWidget the widget this document belongs with
  462.      */
  463.     virtual bool initDoc(InitDocFlags flags, QWidget* parentWidget=0) = 0;
  464.  
  465.     /**
  466.      * Creates and shows the start up widget.
  467.      * @param parent the KoMainWindow used as parent for the widget.
  468.      * @param alwaysShow always show the widget even if the user has configured it to not show.
  469.      * @since 1.5
  470.      */
  471.     virtual void showStartUpWidget(KoMainWindow* parent, bool alwaysShow = false);
  472.  
  473.     /**
  474.      *  Sets the modified flag on the document. This means that it has
  475.      *  to be saved or not before deleting it.
  476.      */
  477.     virtual void setModified( bool _mod );
  478.  
  479.     /**
  480.      *  Tells the document that its title has been modified, either because
  481.      *  the modified status changes (this is done by setModified() ) or
  482.      *  because the URL or the document-info's title changed.
  483.      */
  484.     virtual void setTitleModified();
  485.  
  486.     /**
  487.      *  @return true if the document is empty.
  488.      */
  489.     virtual bool isEmpty() const { return m_bEmpty; }
  490.  
  491.     /**
  492.      *  @brief Sets the document to empty.
  493.      *
  494.      *  Used after loading a template
  495.      *  (which is not empty, but not the user's input).
  496.      *
  497.      *  @see isEmpty()
  498.      */
  499.     virtual void setEmpty() { m_bEmpty = true; }
  500.  
  501.     /**
  502.      *  @brief Loads a document from a store.
  503.      *
  504.      *  You should never have to reimplement.
  505.      *
  506.      *  @param store The store to load from
  507.      *  @param url An internal url, like tar:/1/2
  508.      */
  509.     virtual bool loadFromStore( KoStore* store, const QString& url );
  510.  
  511.     /**
  512.      *  @brief Loads an OASIS document from a store.
  513.      *  This is used for both the main document and embedded objects.
  514.      */
  515.     virtual bool loadOasisFromStore( KoStore* store );
  516.  
  517.     /**
  518.      *  @brief Saves a document to a store.
  519.      *
  520.      *  You should not have to reimplement this - but call it in saveChildren().
  521.      */
  522.     virtual bool saveToStore( KoStore* store, const QString& path );
  523.  
  524.     /**
  525.      *  Reimplement this method to load the contents of your %KOffice document,
  526.      *  from the XML document. This is for the pre-Oasis file format (maindoc.xml).
  527.      *
  528.      *  You are supposed to use the QDomDocument. The QIODevice is provided only
  529.      *  for the cases where some pre-processing is needed, like kpresenter's kprconverter.
  530.      *  Note that the QIODevice could be 0L, when called from an import filter.
  531.      */
  532.     virtual bool loadXML( QIODevice *, const QDomDocument & doc ) = 0;
  533.  
  534.     /**
  535.      *  Reimplement this method to load the contents of your %KOffice document,
  536.      *  from the XML document ("content.xml"). The styles have been parsed already,
  537.      *  you can find them in the oasisStyles parameter. The store can be used
  538.      *  to load images and embedded documents.
  539.      */
  540.     virtual bool loadOasis( const QDomDocument & doc, KoOasisStyles& oasisStyles,
  541.                             const QDomDocument & settings, KoStore* store ) = 0;
  542.  
  543.     /**
  544.      *  Reimplement this method to save the contents of your %KOffice document,
  545.      *  using the OASIS format.
  546.      */
  547.     virtual bool saveOasis( KoStore* store, KoXmlWriter* manifestWriter ) = 0;
  548.  
  549.     /**
  550.      *  Reimplement this to save the contents of the %KOffice document into
  551.      *  a QDomDocument. The framework takes care of saving it to the store.
  552.      */
  553.     virtual QDomDocument saveXML();
  554.  
  555.     /**
  556.      *  Return a correctly created QDomDocument for this KoDocument,
  557.      *  including processing instruction, complete DOCTYPE tag (with systemId and publicId), and root element.
  558.      *  @param tagName the name of the tag for the root element
  559.      *  @param version the DTD version (usually the application's version).
  560.      *  @deprecated use createOasisXmlWriter instead
  561.      */
  562.     QDomDocument createDomDocument( const QString& tagName, const QString& version ) const;
  563.  
  564.     /**
  565.      *  Return an XML writer for saving Oasis XML into the device @p dev,
  566.      *  including the XML processing instruction,
  567.      *  and the root element with all its namespaces.
  568.      *  You can add more namespaces afterwards with addAttribute.
  569.      *
  570.      *  @param dev the device into which the XML will be written.
  571.      *  @param rootElementName the tag name of the root element.
  572.      *     This is either office:document, office:document-content,
  573.      *     office:document-styles, office:document-meta or office:document-settings
  574.      *  @return the KoXmlWriter instance. It becomes owned by the caller, which
  575.      *  must delete it at some point.
  576.      *
  577.      * Once done with writing the contents of the root element, you
  578.      * will need to call endElement(); endDocument(); before destroying the KoXmlWriter.
  579.      * @note OASIS-specific
  580.      */
  581.     static KoXmlWriter* createOasisXmlWriter( QIODevice* dev, const char* rootElementName );
  582.  
  583.     /**
  584.      *  Return a correctly created QDomDocument for an old (1.3-style) %KOffice document,
  585.      *  including processing instruction, complete DOCTYPE tag (with systemId and publicId), and root element.
  586.      *  This static method can be used e.g. by filters.
  587.      *  @param appName the app's instance name, e.g. kword, kspread, kpresenter etc.
  588.      *  @param tagName the name of the tag for the root element, e.g. DOC for kword/kpresenter.
  589.      *  @param version the DTD version (usually the application's version).
  590.      */
  591.     static QDomDocument createDomDocument( const QString& appName, const QString& tagName, const QString& version );
  592.  
  593.     /**
  594.      *  The first thing to do in loadOasis is get hold of the office:body tag, then its child.
  595.      *  If the child isn't the expected one, the error message can indicate what it is instead.
  596.      *  This method returns a translated name for the type of document,
  597.      *  e.g. i18n("Word Processing") for office:text.
  598.      */
  599.     static QString tagNameToDocumentType( const QString& localName );
  600.  
  601.     /**
  602.      *  Save the document. The default implementation is to call
  603.      *  saveXML(). This method exists only for applications that
  604.      *  don't use QDomDocument for saving, i.e. kword and kpresenter.
  605.      */
  606.     virtual bool saveToStream( QIODevice * dev );
  607.  
  608.     /**
  609.      *  Loads a document in the native format from a given URL.
  610.      *  Reimplement if your native format isn't XML.
  611.      *
  612.      *  @param file the file to load - usually KReadOnlyPart::m_file or the result of a filter
  613.      */
  614.     virtual bool loadNativeFormat( const QString & file );
  615.  
  616.     /**
  617.      *  Saves the document in native format, to a given file
  618.      *  You should never have to reimplement.
  619.      *  Made public for writing templates.
  620.      */
  621.     virtual bool saveNativeFormat( const QString & file );
  622.  
  623.     /**
  624.      * Activate/deactivate/configure the autosave feature.
  625.      * @param delay in seconds, 0 to disable
  626.      */
  627.     void setAutoSave( int delay );
  628.  
  629.     /**
  630.      * Checks whether the document is currently in the process of autosaving
  631.      */
  632.     bool isAutosaving() const;
  633.  
  634.     /**
  635.      * Set whether the next openURL call should check for an auto-saved file
  636.      * and offer to open it. This is usually true, but can be turned off
  637.      * (e.g. for the preview module).
  638.      */
  639.     void setCheckAutoSaveFile( bool b );
  640.  
  641.     /**
  642.      * Set whether the next openURL call should show error message boxes in case
  643.      * of errors. This is usually the case, but e.g. not when generating thumbnail
  644.      * previews.
  645.      */
  646.     void setAutoErrorHandlingEnabled( bool b );
  647.  
  648.     /**
  649.      * Checks whether error message boxes should be shown.
  650.      * @since 1.3.1
  651.      */
  652.     bool isAutoErrorHandlingEnabled() const;
  653.  
  654.     /**
  655.      * Retrieve the default value for autosave in seconds.
  656.      * Called by the applications to use the correct default in their config
  657.      */
  658.     static int defaultAutoSave() { return s_defaultAutoSave; }
  659.  
  660.     /**
  661.      * @return the list of all children. Do not modify the
  662.      *         returned list.
  663.      */
  664.     const QPtrList<KoDocumentChild>& children() const;
  665.  
  666.     /**
  667.      * @return the KoDocumentChild associated with the given Document, but only if
  668.      *         @p doc is a direct child of this document.
  669.      *
  670.      * This is a convenience function. You could get the same result
  671.      * by traversing the list returned by children().
  672.      */
  673.     KoDocumentChild *child( KoDocument *doc );
  674.  
  675.     /**
  676.      * @return the information concerning this document.
  677.      * @see KoDocumentInfo
  678.      */
  679.     KoDocumentInfo *documentInfo() const;
  680.  
  681.     void setViewBuildDocument( KoView *view, const QDomDocument &doc );
  682.     QDomDocument viewBuildDocument( KoView *view );
  683.  
  684.     /**
  685.      * Appends the shell to the list of shells which show this
  686.      * document as their root document.
  687.      *
  688.      * This method is automatically called from KoMainWindow::setRootDocument,
  689.      * so you dont need to call it.
  690.      */
  691.     virtual void addShell( KoMainWindow *shell );
  692.  
  693.     /**
  694.      * Removes the shell from the list. That happens automatically if the shell changes its
  695.      * root document. Usually you dont need to call this method.
  696.      */
  697.     virtual void removeShell( KoMainWindow *shell );
  698.  
  699.     /**
  700.      * @return the list of shells for the main window
  701.      */
  702.     const QPtrList<KoMainWindow>& shells() const;
  703.  
  704.     /**
  705.      * @return the number of shells for the main window
  706.      */
  707.     int shellCount() const;
  708.  
  709.     /**
  710.      * @return the list of all the currently opened documents
  711.      */
  712.     static QPtrList<KoDocument> *documentList() { return s_documentList; }
  713.  
  714.     /**
  715.      * @brief Return a DCOP interface for this document
  716.      *
  717.      * %KOffice parts are strongly recommended to reimplement this method,
  718.      * so that their DCOP interface provides more functionality than the basic KoDocumentIface
  719.      */
  720.     virtual DCOPObject * dcopObject();
  721.  
  722.     /**
  723.      * @return the ID of the DCOP interface for this document.
  724.      **/
  725.     QCString dcopObjectId() const;
  726.  
  727.     /**
  728.      * Signal the progress of operations such as loading or saving.
  729.      */
  730.     void emitProgress( int value ) { emit sigProgress( value ); }
  731.  
  732.     bool isInOperation() const;
  733.     virtual void emitBeginOperation();
  734.     virtual void emitEndOperation();
  735.  
  736.     /**
  737.      * Return true if url() is a real filename, false if url() is
  738.      * an internal url in the store, like "tar:/..."
  739.      */
  740.     virtual bool isStoredExtern() const;
  741.  
  742.     /**
  743.      * @return the page layout associated with this document (margins, pageSize, etc).
  744.      * Override this if you want to provide different sized pages.
  745.      *
  746.      * @see KoPageLayout
  747.      */
  748.     virtual KoPageLayout pageLayout(int pageNumber = 0) const;
  749.  
  750.     /**
  751.      * Performs a cleanup of unneeded backup files
  752.      */
  753.     void removeAutoSaveFiles();
  754.  
  755.     void setBackupFile( bool _b );
  756.  
  757.     bool backupFile()const;
  758.  
  759.     /**
  760.      * Returns true if this document or any of its internal child documents are modified.
  761.      */
  762.     bool isModified() const;
  763.  
  764.     /**
  765.      * Returns true during loading (openURL can be asynchronous)
  766.      */
  767.     bool isLoading() const;
  768.  
  769.     int queryCloseExternalChildren();
  770.     int queryCloseDia();
  771.  
  772.     /**
  773.      * @brief Set when we do not want to save external children when saving our 'main' doc.
  774.      *
  775.      * This makes it possible to save 'main' doc + all its internal children first, then
  776.      * go on to save external children. Typically used by query close.
  777.      * Use:
  778.      * @code
  779.      *      doc->setDoNotSaveExtDoc();
  780.      *      doc->save();    // saves doc and its internal children,
  781.      *                            //also calls saveExternalChildren() which sets setDoNotSaveExtDoc(false)
  782.      *      doc->saveExternalChildren();
  783.      * @endcode
  784.      */
  785.     void setDoNotSaveExtDoc( bool on = true );
  786.  
  787.     /**
  788.      * Sets the backup path of the document
  789.      */
  790.     void setBackupPath( const QString & _path );
  791.  
  792.     /**
  793.      * @return path to the backup document
  794.      */
  795.     QString backupPath()const;
  796.  
  797.     /**
  798.      * Indicates that this document is currently viewed
  799.      * and thus should control the title caption.
  800.      * Also resets current flag for all parents.
  801.      */
  802.     void setCurrent( bool on = true );
  803.  
  804.     /**
  805.      * Sets current flag for this document and all its parents
  806.      */
  807.     void forceCurrent( bool on );
  808.     bool isCurrent() const;
  809.  
  810.     void setTitleModified( const QString caption, bool mod );
  811.  
  812.     /**
  813.      * Sets the document URL to empty URL
  814.      * KParts doesn't allow this, but %KOffice apps have e.g. templates
  815.      * After using loadNativeFormat on a template, one wants
  816.      * to set the url to KURL()
  817.      */
  818.     void resetURL() { m_url = KURL(); m_file = QString::null; }
  819.  
  820.     /**
  821.      * Set when you want an external embedded document to be stored internally
  822.      */
  823.     void setStoreInternal( bool i );
  824.  
  825.     /**
  826.      * @return true when external embedded documents are stored internally
  827.      */
  828.     bool storeInternal() const;
  829.  
  830.     bool hasExternURL() const;
  831.  
  832.     /**
  833.      * Sets the document URL to @p url
  834.      * KParts doesn't really allow this, but it is needed for undo of setStoreInternal()
  835.      */
  836.     void setURL( const KURL& url ) { m_url = url; }
  837.  
  838.     /**
  839.      * _Only_ use these functions to restore m_file (in KoMainWindow) after a
  840.      * failed save (remember to use setURL() to restore the URL as well).
  841.      *
  842.      * @warning Do _not_ use these functions for any other purpose.
  843.      *
  844.      * @internal
  845.      */
  846.     QString &file() { return m_file; }
  847.  
  848.     /**
  849.      * _Only_ use these functions to restore m_file (in KoMainWindow) after a
  850.      * failed save (remember to use setURL() to restore the URL as well).
  851.      *
  852.      * @warning Do _not_ use these functions for any other purpose.
  853.      *
  854.      * @internal
  855.      */
  856.     void setFile( const QString &file ) { m_file = file; }
  857.  
  858.     /**
  859.      * @internal (public for KoMainWindow)
  860.      */
  861.     void setMimeTypeAfterLoading( const QString& mimeType );
  862.  
  863.     /**
  864.      * @return returns the number of pages in the document.
  865.      */
  866.     virtual int pageCount() const { return 1; }
  867.  
  868.     /**
  869.      * @return all kotext-based text objects in the document
  870.      * This is used by some text-analyzer plugins.
  871.      * @since 1.5
  872.      */
  873.     virtual QValueList<KoTextDocument *> allTextDocuments() const;
  874.  
  875.     /**
  876.      * Returns the unit used to display all measures/distances.
  877.      * @since 1.5
  878.      */
  879.     KoUnit::Unit unit() const;
  880.  
  881.     /**
  882.      * Sets the unit used to display all measures/distances.
  883.      * @since 1.5
  884.      */
  885.     void setUnit( KoUnit::Unit u );
  886.  
  887.     /**
  888.      * Returns the name of the unit used to display all measures/distances.
  889.      * Use this method for displaying it in the user interface, but use
  890.      * unit() for everything else (conversions etc.)
  891.      * @since 1.5
  892.      */
  893.     QString unitName() const;
  894.  
  895.     /**
  896.      * Set the template type used. This is used by the start up widget to show
  897.      * the correct templates.
  898.      * @since 1.5
  899.      */
  900.     void setTemplateType(const QString& _templateType);
  901.     /**
  902.      * Template type used. This is used by the start up widget to show
  903.      * the correct templates.
  904.      * @since 1.5
  905.      */
  906.     QString templateType() const;
  907.  
  908.     /**
  909.      * Shows the init dialog when embeding
  910.      * @param parent the parent widget
  911.      * @since 1.5
  912.      */
  913.     virtual bool showEmbedInitDialog(QWidget* parent);
  914.  
  915. public slots:
  916.     /**
  917.      * Initialize an empty document using default values
  918.      * @since 1.5
  919.      */
  920.     virtual void initEmpty();
  921.  
  922. signals:
  923.  
  924.     /**
  925.      * This signal is emitted when the unit is changed by setUnit()
  926.      * It is common to connect views to it, in order to change the displayed units
  927.      * (e.g. in the rulers)
  928.      */
  929.     void unitChanged(KoUnit::Unit);
  930.  
  931.     /**
  932.      * This signal is emitted when a direct or indirect child document changes
  933.      * and needs to be updated in all views.
  934.      *
  935.      * If one of your child documents emits the childChanged signal, then you may
  936.      * usually just want to redraw this child. In this case you can ignore the parameter
  937.      * passed by the signal.
  938.      */
  939.     void childChanged( KoDocumentChild *child );
  940.  
  941.     /**
  942.      * Progress info while loading or saving. The value is in percents (i.e. a number between 0 and 100)
  943.      * Your KoDocument-derived class should emit the signal now and then during load/save.
  944.      * KoMainWindow will take care of displaying a progress bar automatically.
  945.      */
  946.     void sigProgress( int value );
  947.  
  948.     /**
  949.      * Emitted e.g. at the beginning of a save operation
  950.      * This is emitted by KoDocument and used by KoView to display a statusbar message
  951.      */
  952.     void sigStatusBarMessage( const QString& text );
  953.  
  954.     /**
  955.      * Emitted e.g. at the end of a save operation
  956.      * This is emitted by KoDocument and used by KoView to clear the statusbar message
  957.      */
  958.     void sigClearStatusBarMessage();
  959.  
  960.     void sigBeginOperation();
  961.     void sigEndOperation();
  962.  
  963.     /**
  964.     * Emitted when the document is modified
  965.     */
  966.     void modified( bool );
  967.  
  968.     void closeEmbedInitDialog();
  969.  
  970. protected slots:
  971.     /**
  972.      * This slot loads an existing file and deletes the start up widget.
  973.      * @param file the file to load (including path)
  974.      * @since 1.5
  975.      */
  976.     virtual void openExistingFile( const QString& file );
  977.     /**
  978.      * This slot loads a template and deletes the start up widget.
  979.      * @param file the template to load
  980.      * @since 1.5
  981.      */
  982.     virtual void openTemplate( const QString& file );
  983.  
  984.     void deleteOpenPaneDelayed();
  985.  
  986. protected:
  987.  
  988.     QString autoSaveFile( const QString & path ) const;
  989.  
  990.     virtual KoView *createViewInstance( QWidget *parent, const char *name ) = 0;
  991.  
  992.     /**
  993.      *  Loads a document from KReadOnlyPart::m_file (KParts takes care of downloading
  994.      *  remote documents).
  995.      *  Applies a filter if necessary, and calls loadNativeFormat in any case
  996.      *  You should not have to reimplement, except for very special cases.
  997.      *
  998.      * This method is called from the KReadOnlyPart::openURL method.
  999.      */
  1000.     virtual bool openFile();
  1001.  
  1002.     /**
  1003.      *  Saves a document to KReadOnlyPart::m_file (KParts takes care of uploading
  1004.      *  remote documents)
  1005.      *  Applies a filter if necessary, and calls saveNativeFormat in any case
  1006.      *  You should not have to reimplement, except for very special cases.
  1007.      */
  1008.     virtual bool saveFile();
  1009.  
  1010.     /**
  1011.      * Override this method in your derived class to show a widget in the startup 'dialog'.
  1012.      * This widget should allow the user to set settings for a custom document (i.e. one
  1013.      * not based on a template).
  1014.      * The returned widget should provide its own button (preferrably 'Create') and
  1015.      * implement the logic to implement the document instance correctly.
  1016.      * After initializing the widget should emit a signal called 'documentSelected()' which
  1017.      * will remove the startupWidget and show the document.
  1018.      * @param parent the parent of the to be created widget.
  1019.      */
  1020.     virtual QWidget* createCustomDocumentWidget(QWidget *parent);
  1021.  
  1022.     /**
  1023.      *  OLD XML method. For OASIS just call KoDocumentChild::loadOasisDocument
  1024.      *  after KoDocumentChild::loadOasis.
  1025.      *
  1026.      *  You need to overload this function if your document may contain
  1027.      *  embedded documents. This function is called to load embedded documents.
  1028.      *
  1029.      *  An example implementation may look like this:
  1030.      *  @code
  1031.      *  QPtrListIterator<KoDocumentChild> it( children() );
  1032.      *  for( ; it.current(); ++it )
  1033.      *  {
  1034.      *    if ( !it.current()->loadDocument( _store ) )
  1035.      *    {
  1036.      *      return false;
  1037.      *    }
  1038.      *  }
  1039.      *  return true;
  1040.      *  @endcode
  1041.      */
  1042.     virtual bool loadChildren( KoStore* );
  1043.  
  1044.     /**
  1045.      *  Saves all internal children (only!).
  1046.      *  @see saveExternalChildren if you have external children.
  1047.      *  Returns true on success.
  1048.      */
  1049.     virtual bool saveChildren( KoStore* store );
  1050.  
  1051.     /**
  1052.      *  Saves all internal children (only!), to the store, using the OASIS format.
  1053.      *  This is called automatically during saveNativeFormat.
  1054.      *  @see saveExternalChildren if you have external children.
  1055.      *  Returns true on success.
  1056.      */
  1057.     virtual bool saveChildrenOasis( KoStore* store, KoXmlWriter* manifestWriter );
  1058.  
  1059.     /**
  1060.      *  Overload this function if you have to load additional files
  1061.      *  from a store. This function is called after loadXML()
  1062.      *  and after loadChildren() have been called.
  1063.      */
  1064.     virtual bool completeLoading( KoStore* store );
  1065.  
  1066.     /**
  1067.      *  If you want to write additional files to a store,
  1068.      *  then you must do it here.
  1069.      *  In the implementation, you should prepend the document
  1070.      *  url (using url().url()) before the filename, so that everything is kept relative
  1071.      *  to this document. For instance it will produce urls such as
  1072.      *  tar:/1/pictures/picture0.png, if the doc url is tar:/1
  1073.      *  But do this ONLY if the document is not stored extern (see isStoredExtern() ).
  1074.      *  If it is, then the pictures should be saved to tar:/pictures.
  1075.      */
  1076.     virtual bool completeSaving( KoStore* store );
  1077.  
  1078.     /**
  1079.      * Inserts the new child in the list of children and emits the
  1080.      * childChanged() signal.
  1081.      *
  1082.      * At the same time this method marks this document as modified.
  1083.      *
  1084.      * To remove a child, just delete it. KoDocument will detect this
  1085.      * and remove the child from its lists.
  1086.      *
  1087.      * @see #isModified
  1088.      */
  1089.     virtual void insertChild( KoDocumentChild *child );
  1090.  
  1091.     /** @internal */
  1092.     virtual void setModified() { KParts::ReadWritePart::setModified(); }
  1093.  
  1094.     /** @internal */
  1095.     virtual void insertChild(QObject *o) { QObject::insertChild(o); }
  1096.  
  1097.     KoPageLayout m_pageLayout;
  1098.  
  1099.     /**
  1100.      *  Saves all externally stored children.
  1101.      *  Returns true on success.
  1102.      * @see #saveChildren for internal children
  1103.      */
  1104.     virtual bool saveExternalChildren();
  1105.  
  1106.     /**
  1107.      *  Returns whether or not the current openURL() or openFile() call is
  1108.      *  actually an import operation (like File --> Import).
  1109.      *  This is for informational purposes only.
  1110.      */
  1111.     bool isImporting() const;
  1112.  
  1113.     /**
  1114.      *  Returns whether or not the current saveFile() call is actually an export
  1115.      *  operation (like File --> Export).
  1116.      *  If this function returns true during saveFile() and you are changing
  1117.      *  some sort of state, you _must_ restore it before the end of saveFile();
  1118.      *  otherwise, File --> Export will not work properly.
  1119.      */
  1120.     bool isExporting() const;
  1121.  
  1122.     /**
  1123.      * Creates the open widget showed at application start up.
  1124.      * @param parent the parent widget
  1125.      * @param instance the KInstance to be used for KConfig data
  1126.      * @param templateType the template-type (group) that should be selected on creation.
  1127.      * @since 1.5
  1128.      */
  1129.     KoOpenPane* createOpenPane( QWidget* parent, KInstance* instance,
  1130.                                 const QString& templateType = QString::null);
  1131.  
  1132. private slots:
  1133.     void slotChildChanged( KoChild *c );
  1134.     void slotChildDestroyed();
  1135.     void slotAutoSave();
  1136.     void slotStarted( KIO::Job* );
  1137.     void startCustomDocument();
  1138.     /**
  1139.      * Removes the open widget showed at application start up.
  1140.      * @since 1.5
  1141.      */
  1142.     void deleteOpenPane();
  1143.  
  1144. private:
  1145.     KService::Ptr nativeService();
  1146.     bool oldLoadAndParse( KoStore* store, const QString& filename, QDomDocument& doc );
  1147.     bool loadNativeFormatFromStore( const QString& file );
  1148.     bool savePreview( KoStore* store );
  1149.     bool saveOasisPreview( KoStore* store, KoXmlWriter* manifestWriter );
  1150.     class Private;
  1151.     Private *d;
  1152.     KService::Ptr m_nativeService;
  1153.     bool m_bEmpty;
  1154.     static QPtrList<KoDocument> *s_documentList;
  1155.     static const int s_defaultAutoSave;
  1156. };
  1157.  
  1158. #endif
  1159.